// pages/login/login.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    userName : '',
    password : '',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    to: function(){
      wx.navigateTo({
        url: '/pages/register/register',
      })

    },

    login: function () {
      var that = this;
      console.log(that.data.userName);
      console.log(that.data.password);
      wx.request({
        url: 'http://120.79.197.164:9285/barter/user/login',
        method: 'POST',
        data: {
          "userName": that.data.userName,
          "password": that.data.password,
        },
        header: {
          'content-type': 'application/json'
        },
        success(res){
          if (res.data.data != null){
            wx.setStorageSync('isLogin', true);
            wx.setStorageSync('uuid', res.data.data.id);
            wx.switchTab({
              url: '/pages/index/index',
            })
          }

        }
      })

    },

    bindValue : function(e){
      // 表单双向数据绑定
      var that = this;
      var dataset = e.target.dataset;
      // data-开头的是自定义属性，可以通过dataset获取到，dataset是一个json对象
      var name = dataset.name;
      var value = e.detail.value;
      // 拼接对象属性名，用于为对象属性赋值
      var attributeName = 'dataList.' + name
      that.data[name] = value;
      that.setData({
        [attributeName]: that.data[name]
      });
      // console.log(that.data.goodList);

    }

  }
})
